﻿using System;

using Framework.Validation;
using Framework.Validation.Vab;

using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace Framework.Domain.Validation.Vab
{
    /// <summary>
    /// Provides ability to manage creation of <see cref="VabDomainObjectValidator" /> instances.
    /// </summary>
    public class VabDomainObjectValidatorFactory : IValidatorFactory
    {
        private const string DefaultRuleSetName = "default";

        private static IValidator InnerCreate<T>(string ruleSetName)
        {
            Validator vabValidator = ValidationFactory
                .CreateValidatorFromConfiguration<T>(ruleSetName);

            IValidator validator = new VabValidatorWrapper(vabValidator);

            return validator;
        }

        /// <inheritdoc />
        public IValidator Create<T>()
        {
            IValidator validator = InnerCreate<T>(DefaultRuleSetName);

            return validator;
        }

        /// <inheritdoc />
        public IValidator Create<T>(string ruleSetName)
        {
            IValidator validator = InnerCreate<T>(ruleSetName);

            return validator;
        }
    }
}
